home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / componentEditorWindow.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  15.7 KB  |  577 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  10 Nov 1998
  22. //  Author:         spam
  23. //
  24. //  Description:
  25. //      Procs for creating the Component Editor Window.
  26. //    
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29.  
  30.  
  31. //  Procedure Name:
  32. //      compEdPrecisionPrompt
  33. //
  34. //  Description:
  35. //      Prompts user to enter a new integer for the number of decimal 
  36. //        points to show.
  37. //
  38. //  Return Value:
  39. //      None.
  40. //
  41. global proc compEdPrecisionPrompt () 
  42. {
  43.     int $oldPrecision = `optionVar -query CEPrecision`;
  44.     int $newPrecision = precisionPrompt ("componentEditorPanel1Window", $oldPrecision, 15);
  45.     if ($newPrecision > 0) {
  46.         componentEditor -edit -pre $newPrecision componentEditorPanel1WindowComponEditor;
  47.         optionVar -iv CEPrecision $newPrecision;
  48.     }
  49. }
  50.  
  51.  
  52. global proc buildCompEdContextHelpItems(string $nameRoot, string $menuParent)
  53. //
  54. //  Description:
  55. //        Build context sensitive menu items for the hyper graph.  
  56. //        
  57. //  Input Arguments:
  58. //        $nameRoot - name to use as the root of all item names
  59. //        $menuParent - the name of the parent of this menu
  60. //
  61. //  Return Value:
  62. //      None
  63. //
  64. {
  65.     menuItem -label "Help on Component Editor..."
  66.         -enableCommandRepeat false
  67.         -command "showHelp ComponentEditor";
  68. }
  69.  
  70.  
  71. //
  72. //  Procedure Name:
  73. //      buildCompEdMenus
  74. //
  75. //  Description:
  76. //      Build all of the menus needed for the component editor window
  77. //    
  78. //  Input Arguments:
  79. //        string $compEdName - the name of the component editor
  80. //    
  81. //  Return Value:
  82. //      None
  83. //
  84. global proc buildCompEdMenus(string $compEdName) {
  85.  
  86.   int $isChecked;
  87.  
  88.   // assume that the menu parent is properly set.
  89.   //
  90.   menu -l "List" 
  91.     -tearOff true
  92.     -postMenuCommandOnce true
  93.     -familyImage "menuIconOptions.xpm";
  94.  
  95.   // the menuItems
  96.   //
  97.   // autoupdate = default to on
  98.   //
  99.   if(`optionVar -exists CEAutoUpdate`) {
  100.     $isChecked = `optionVar -q CEAutoUpdate`;
  101.   } else {
  102.     $isChecked = true;
  103.     optionVar -iv CEAutoUpdate true;
  104.   }
  105.   string $mitem = `menuItem -l "Auto Update" -checkBox $isChecked
  106.     -command ("compEdMenuCmd CEMIAutoUpdate " + $compEdName)
  107.     "CEMIAutoUpdate"`;
  108.  
  109.   string $mitem = `menuItem -l "Load Selected Components"
  110.     -command ("compEdMenuCmd CEMILoad " + $compEdName)
  111.     "CEMILoad"`;
  112.  
  113.   // showAllCols defaults to on
  114.   //
  115.   int $showCols;
  116.   if(`optionVar -exists CEShowAllCols`) {
  117.       $showCols = `optionVar -q CEShowAllCols`;
  118.   } else {
  119.       $showCols = true;
  120.       optionVar -iv CEShowAllCols true;
  121.   }
  122.   string $mitem = `menuItem -l "Show All Columns" -checkBox $showCols
  123.     -command ("compEdMenuCmd CEMIShowAllCols " + $compEdName)
  124.     -annotation "Show All Columns: Turn off to hide columns that contain only zero values"
  125.     "CEMIShowAllCols"`;
  126.  
  127.   // show path name defaults to on
  128.   //
  129.   int $showPathName;
  130.   if(`optionVar -exists CEShowPathName`) {
  131.       $showPathName = `optionVar -q CEShowPathName`;
  132.   } else {
  133.       $showCols = true;
  134.       optionVar -iv CEShowPathName true;
  135.   }
  136.   string $mitem = `menuItem -l "Show Path Name" -checkBox $showPathName
  137.     -command ("compEdMenuCmd CEMIShowPathName " + $compEdName)
  138.     -annotation "Show Path Name: Turn off to hide path names and only show object name"
  139.     "CEMIShowPathName"`;
  140.  
  141.  
  142.   menuItem -label "Change Precision..." -command "compEdPrecisionPrompt";
  143.  
  144.   setParent -menu ..;
  145.  
  146.   // Add support for the Context Sensitive Help Menu.
  147.   //
  148.   addContextHelpProc $compEdName "buildCompEdContextHelpItems";
  149. //  doHelpMenu($compEdName, $compEdName); 
  150. }
  151.  
  152. ////////////////////////////////////////////////////////////////////////////////
  153. //
  154. //  Procedure Name:
  155. //      compEdMenuCmd
  156. //
  157. //  Description:
  158. //      The command called by all comp ed menus
  159. //    
  160. //  Input Arguments:
  161. //        string $itemName - the nema of the menuItem
  162. //        string $compEdName - the name of the component editor
  163. //    
  164. //  Return Value:
  165. //      None
  166. //
  167. global proc compEdMenuCmd(string $itemName, string $compEdName) {
  168.  
  169.     if( `menuItem -exists $itemName` ) {
  170.  
  171.         if ($itemName == "CEMIAutoUpdate") {
  172.         
  173.             int $isChecked = `menuItem -q -checkBox $itemName`;
  174.  
  175.             if($isChecked) {
  176.                 componentEditor -e -li false $compEdName;
  177.             } else {
  178.                 componentEditor -e -li true $compEdName;
  179.             }
  180.         } else if ($itemName == "CEMILoad") {
  181.             componentEditor -e -li false $compEdName;
  182.             componentEditor -e -li true $compEdName;
  183.         } else if ($itemName == "CEMIShowAllCols") {
  184.             int $isChecked = `menuItem -q -checkBox $itemName`;
  185.  
  186.             if($isChecked) {
  187.                 componentEditor -e -hzc false $compEdName;
  188.             } else {
  189.                 componentEditor -e -hzc true $compEdName;
  190.             }
  191.         } else if ($itemName == "CEMIShowPathName") {
  192.             int $isChecked = `menuItem -q -checkBox $itemName`;
  193.  
  194.             if($isChecked) {
  195.                 componentEditor -e -hpn false $compEdName;
  196.             } else {
  197.                 componentEditor -e -hpn true $compEdName;
  198.             }
  199.         }
  200.     }
  201. }
  202.  
  203. ////////////////////////////////////////////////////////////////////////////////
  204. //
  205. //  Procedure Name:
  206. //      setTabOpType
  207. //
  208. //  Description:
  209. //      Set the given componentEditor to the currentTabIndex-1 th
  210. //    opeartionType, or to a hardcoded given value.
  211. //    
  212. //  Input Arguments:
  213. //        string $tabLayoutName - name of the tab layout in the window
  214. //        string $compEdName - name of the component editor in the window
  215. //        int $set - if not -1, will set the tabLayout to that number.
  216. //                if -1, will query the tabLayout. So When the editor first
  217. //                comes up, set will be a saved value, allowing the editor
  218. //                the last tab it was open to. The -1 is used as a parameter
  219. //                when this command is added as tab changed command.
  220. //
  221. //  Return Value:
  222. //      None
  223. //
  224. global proc setTabOpType(string $tabLayoutName, string $compEdName, int $set) {
  225.  
  226.     if (`tabLayout -exists $tabLayoutName`) {
  227.         int $currentTab = $set;
  228.         if( $set == -1) {
  229.             $currentTab = `tabLayout -q -selectTabIndex $tabLayoutName`;
  230.         }
  231.  
  232.         optionVar -intValue "CEoperationType" $currentTab;
  233.  
  234.         // subtract 1 since tabs are a 1-based index, and 
  235.         // component editor uses a zero based index.
  236.         //
  237.         $currentTab -= 1;
  238.  
  239.         // for safety's sake, verify that the current tab is valid.
  240.         //
  241.         int $maxTabs = `componentEditor -q -operationCount $compEdName`;
  242.          if($currentTab <= $maxTabs) {
  243.             componentEditor -e -operationType $currentTab $compEdName;
  244.          }
  245.     }
  246. }
  247.  
  248.  
  249. ////////////////////////////////////////////////////////////////////////////////
  250. //
  251. //  Procedure Name:
  252. //      updateComponentEditorSliderRange
  253. //
  254. //  Description:
  255. //      Callback for when a value is changed in one of the fields that 
  256. //        controls the slider's range
  257. //    
  258. //  Input Arguments:
  259. //      $slider - the slider used to edit groups of values in the component
  260. //                  editor
  261. //      $minField - field for setting the min value of the slider
  262. //      $maxField - field for setting the max value of the slider
  263. //
  264. //  Return Value:
  265. //      None
  266. //
  267. global proc updateComponentEditorSliderRange( string $slider, 
  268.                                               string $minField, 
  269.                                               string $maxField ) 
  270. {            
  271.     float $min, $max;
  272.     
  273.     $min = `floatField -q -value $minField`;
  274.     $max = `floatField -q -value $maxField`;
  275.  
  276.  
  277.     if ( $max > $min ) {
  278.         floatSlider -e -minValue $min -maxValue $max $slider;
  279.             
  280.         // Update option vars
  281.         //
  282.         optionVar -fv "componentEditorSliderMin" $min;
  283.         optionVar -fv "componentEditorSliderMax" $max;
  284.     } else {
  285.         warning( "Slider maximum must be greater than minimum" );
  286.     }
  287. }
  288.  
  289. ////////////////////////////////////////////////////////////////////////////////
  290. //
  291. //  Procedure Name:
  292. //      initComponentEditorSlider
  293. //
  294. //  Description:
  295. //      Set up the optionVars and initialize the slider range
  296. //    
  297. //  Input Arguments:
  298. //      $slider - the slider used to edit groups of values in the component
  299. //                  editor
  300. //      $minField - field for setting the min value of the slider
  301. //      $maxField - field for setting the max value of the slider
  302. //
  303. //  Return Value:
  304. //      None
  305. //
  306. proc initComponentEditorSlider( string $slider, string $minField, 
  307.                                        string $maxField ) 
  308. {
  309.     float $min, $max;
  310.  
  311.     // Retrieve min value for slider
  312.     //
  313.     if ( !`optionVar -exists "componentEditorSliderMin"` ) {
  314.         optionVar -fv "componentEditorSliderMin" 0.0;
  315.     }
  316.     $min = `optionVar -q "componentEditorSliderMin"`;
  317.  
  318.     // Retrieve max value for slider
  319.     //
  320.     if ( !`optionVar -exists "componentEditorSliderMax"` ) {
  321.         optionVar -fv "componentEditorSliderMax" 1.0;
  322.     }
  323.     $max = `optionVar -q "componentEditorSliderMax"`;
  324.  
  325.     string $cmd = "updateComponentEditorSliderRange( \"" + $slider 
  326.                   + "\", \"" + $minField + "\", \"" + $maxField + "\");";
  327.  
  328.     floatField -e -changeCommand $cmd -value $min $minField;
  329.     floatField -e -changeCommand $cmd -value $max $maxField;
  330.  
  331.     updateComponentEditorSliderRange( $slider, $minField, $maxField );
  332. }
  333.  
  334.  
  335.  
  336. ////////////////////////////////////////////////////////////////////////////////
  337. //
  338. //  Procedure Name:
  339. //      buildComponentEditorControls
  340. //
  341. //  Description:
  342. //      Build the component editor controls. Assumes a parent 
  343. //    MenuBarLayout has already been created.
  344. //    
  345. //  Input Arguments:
  346. //      None
  347. //
  348. //  Return Value:
  349. //      None
  350. //
  351. global proc buildComponentEditorControls() {
  352.  
  353.     string $parent = `setParent -q`;
  354.  
  355.     // find and isolate the part of the parent name containing 
  356.     // the unique name of the panel
  357.     //
  358.     string $tokens[];
  359.     tokenize ($parent,"|",$tokens);
  360.     int $numTokes = `size $tokens`;
  361.     int $j;
  362.     for ($j = 0; $j < $numTokes; $j++) {
  363.         string $mtchStr = `match $tokens[$j] "componentEditorPanel"`;
  364.         int $num = `size $mtchStr`;
  365.         if( $num == 0 ) {
  366.             break;
  367.         }
  368.     }
  369.     
  370.     // Get the decimal precision
  371.     //
  372.     int $precision;
  373.     if (!`optionVar -exists CEPrecision`) {
  374.         optionVar -iv CEPrecision 3;
  375.     }
  376.     $precision = `optionVar -q CEPrecision`;
  377.  
  378.     // make the editor, but don't parent it yet
  379.     //
  380.     if (!`selectionConnection -exists ($tokens[$j] + "CESelCon")`) {
  381.         string $spam = `selectionConnection -activeList -parent $parent ($tokens[$j] + "CESelCon")`;
  382.     } else {
  383.         selectionConnection -e -parent $parent ($tokens[$j] + "CESelCon");
  384.     }
  385.  
  386.     string $edName = ($tokens[$j] + "ComponEditor");
  387.  
  388.     if(!`componentEditor -exists $edName`) {
  389.         $edName = `componentEditor -unParent -pre $precision -mainListConnection ($tokens[$j] + "CESelCon") $edName`;
  390.     } else {
  391.         componentEditor -e -unParent -mainListConnection ($tokens[$j] + "CESelCon") $edName;
  392.     }
  393.  
  394.     // make the menus
  395.     //
  396.     buildCompEdMenus($edName);
  397.  
  398.     string $mainForm = `formLayout compEdForm`;
  399.  
  400.         string $tabLayout = `tabLayout -parent $mainForm compEdTab`;
  401.             tabLayout -e -cc ("setTabOpType " + $tabLayout + " " 
  402.                               + $edName + " -1") $tabLayout;
  403.         setParent ..;
  404.  
  405.          string $frameL = `frameLayout -p $mainForm -l "" compEdFrame`;
  406.             string $compFormLayout = `formLayout`;
  407.                 int $isChecked = `optionVar -q CEAutoUpdate`;
  408.                 componentEditor -e -lockInput (!$isChecked) -parent $compFormLayout 
  409.                     $edName;
  410.  
  411.                 string $floatField = `floatField -width 75`;
  412.                 string $floatSliderMinField = `floatField -precision 2`;
  413.                 string $floatSliderMaxField = `floatField -precision 2`;
  414.                  string $floatSlider = `floatSlider`;
  415.  
  416.                 componentEditor -e -floatSlider $floatSlider -floatField $floatField 
  417.                     $edName;
  418.                 
  419.                 initComponentEditorSlider( $floatSlider, $floatSliderMinField, 
  420.                                            $floatSliderMaxField );
  421.             setParent ..;
  422.         setParent ..;
  423.  
  424.         string $btnForm = `formLayout buttonForm`;
  425.  
  426.             string $rbtn = `button -p $btnForm -l "Load Components" 
  427.                 -c ("componentEditor -e -li false " + $edName + 
  428.                     "; componentEditor -e -li true " + $edName)
  429.             reloadBtn`;
  430.  
  431.             // close button won't exist in a non torn-off panel
  432.             // only make it if we're in a window.
  433.             //
  434.             string $tokens[];
  435.             tokenize($parent,"|",$tokens);
  436.  
  437.             if($tokens[0] != "MayaWindow") {
  438.                 string $cbtn = `button -p $btnForm -l "Close" 
  439.                     -c ("deleteUI " + $tokens[0])
  440.                 closeBtn`;
  441.             }
  442.  
  443.             setParent ..;
  444.         setParent ..;
  445.     setParent ..;
  446.  
  447.     // now construct a command to set the tab labels
  448.     //
  449.  
  450.     // get the tab labels
  451.     //
  452.     string $labels[] = `componentEditor -q -operationLabels $edName`;
  453.  
  454.     // now create children of the tab layout
  455.     //
  456.     setParent $tabLayout;
  457.         int $i, $numTabs = size($labels);
  458.             
  459.         for( $i = 0; $i < $numTabs; $i++ ) {
  460.             formLayout ("compEdTabChild" + $i);
  461.                 separator -style "none";
  462.             setParent ..;
  463.         }
  464.      setParent ..;
  465.  
  466.     string $tabCmd = "tabLayout -e";
  467.     for ($i = 0; $i < $numTabs; $i++ ) {
  468.         $tabCmd += (" -tl compEdTabChild" + $i + " \"" + $labels[$i] + "\"");
  469.     }
  470.     $tabCmd    += " " + $tabLayout;
  471.  
  472.     // now set the labels
  473.     //
  474.     eval $tabCmd;
  475.  
  476.     // now set the tab type to the last remembered one
  477.     //
  478.     int $currentOp = `optionVar -q "CEoperationType"`;
  479.     if($currentOp > 0 && $currentOp < $numTabs) {
  480.         setTabOpType($tabLayout,$edName,$currentOp);
  481.         tabLayout -e -selectTabIndex $currentOp $tabLayout;
  482.     }
  483.  
  484.     // lastly, do the form attachments
  485.     //
  486.     formLayout -e 
  487.         -af compEdTab "top" 0
  488.         -af compEdTab "left" 0 
  489.         -af compEdTab "right" 0 
  490.         -an compEdTab "bottom"
  491.             
  492.          -ac compEdFrame "top" 0 compEdTab
  493. //          -af compEdFrame "top" 0
  494.           -af compEdFrame "right" 0       
  495.           -af compEdFrame "left" 0       
  496.           -af compEdFrame "bottom" 30
  497.  
  498.           -an buttonForm "top"
  499.           -af buttonForm "left" 3
  500.           -af buttonForm "right" 3
  501.           -af buttonForm "bottom" 3
  502.  
  503.     $mainForm;
  504.  
  505.     formLayout -e 
  506.         -af reloadBtn "top" 0
  507.         -af reloadBtn "left" 0 
  508.         -ap reloadBtn "right" 1 50
  509.         -af reloadBtn "bottom" 0
  510.         $btnForm;
  511.     
  512.     formLayout -e 
  513.         -af $edName "top" 0
  514.         -af $edName "left" 0 
  515.         -af $edName "right" 0
  516.         -ac $edName "bottom" 5 $floatField
  517.         -af $floatField "left" 0
  518.         -af $floatField "bottom" 2
  519.         -an $floatField "right"
  520.         -an $floatField "top"
  521.         -ac $floatSliderMinField "left" 10 $floatField
  522.         -af $floatSliderMinField "bottom" 2
  523.         -an $floatSliderMinField "right"
  524.         -an $floatSliderMinField "top"
  525.         -ac $floatSlider "left" 0 $floatSliderMinField
  526.         -ac $floatSlider "right" 0 $floatSliderMaxField
  527.         -an $floatSlider "bottom"
  528.         -aoc $floatSlider "top" 4 $floatSliderMinField
  529.         -af $floatSliderMaxField "right" 0
  530.         -af $floatSliderMaxField "bottom" 2
  531.         -an $floatSliderMaxField "top"
  532.         -an $floatSliderMaxField "left"
  533.         $compFormLayout;
  534.  
  535.     if($tokens[0] != "MayaWindow") {
  536.         formLayout -e 
  537.             -af closeBtn "top" 0
  538.             -ap closeBtn "left" 1 50
  539.             -af closeBtn "right" 0 
  540.             -af closeBtn "bottom" 0
  541.         $btnForm;
  542.     }
  543.  
  544. }
  545.  
  546. ////////////////////////////////////////////////////////////////////////////////
  547. //
  548. //  Procedure Name:
  549. //      componentEditorWindow
  550. //
  551. //  Description:
  552. //      Build the component editor window
  553. //    
  554. //  Input Arguments:
  555. //      None
  556. //
  557. //  Return Value:
  558. //      None
  559. //
  560. global proc componentEditorWindow() {
  561.  
  562.     if ( !`window -exists componentEditorWin` ) {
  563.  
  564.         window -title "Component Editor" 
  565.             -iconName "Components" componentEditorWin;
  566.  
  567.         // now create a menuBarLayout
  568.         //
  569.         string $compEdMenLayout = `menuBarLayout compEdMenLayout`;
  570.  
  571.         buildComponentEditorControls ;
  572.     }
  573.  
  574.     showWindow componentEditorWin;
  575.  
  576. }
  577.